<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>作用域插槽</h2>
      <!-- 作用域插槽就是让我们在插槽里面可以使用子组件的作用域 -->
      <!-- <child v-slot="slotProps">
        <span>{{ slotProps.nickname }} - {{ slotProps.age }}</span>
      </child> -->

      <!-- slotProps也可以直接使用解构 -->
      <child v-slot="{ nickname, age }">
        <span>{{ nickname }} - {{ age }}</span>
      </child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;
      const Child = {
        data() {
          return {
            name: "zhangsan",
          };
        },
        template: `
          <div>
            这是child子组件 - 
            <slot :nickname="name" age="20"></slot>
          </div>
        `,
      };

      const app = createApp({
        data() {
          return {};
        },
        components: {
          Child,
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
